<!DOCTYPE html>
<html>
<head>
    <title>开店</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="description" content="Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description.
		">
    <link href="/static/weui/css/iconfont.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="/static/weui/css/weui.min.css">
    <link rel="stylesheet" href="/static/weui/css/jquery-weui.css">
    <link rel="stylesheet" type="text/css" href="/static/weui/css/demos.css" />
    <style>
        body {
            background: #eee !important;
        }
    </style>
</head>
<body ontouchstart>
<div class="weui_cells weui_cells_form">
    <div class="weui_cell">
        <div class="weui_cell_hd">
            <label class="weui_label">店铺名称</label>
        </div>
        <div class="weui_cell_bd weui_cell_primary">
            <input class="weui_input" type="text" id="name" placeholder="取一个独一无二的名字吧">
        </div>
    </div>
    <div class="weui_cell">
        <div class="weui_cell_hd">
            <label class="weui_label">联系电话</label>
        </div>
        <div class="weui_cell_bd weui_cell_primary">
            <input class="weui_input" type="tel" id="tel" placeholder="店铺客服电话">
        </div>
    </div>
    <div class="weui_cell">
        <div class="weui_cell_hd">
            <label for="name" class="weui_label">店铺类型</label>
        </div>
        <div class="weui_cell_bd weui_cell_primary">
            <input class="weui_input" id="type" type="text" readonly="" data-values="" placeholder="请选择">
        </div>
    </div>
    <div class="weui_cell">
        <div class="weui_cell_bd weui_cell_primary">
            <div class="weui_uploader">
                <div class="weui_uploader_hd weui_cell">
                    <div class="weui_cell_bd weui_cell_primary">
                        店铺LOGO
                    </div>
                </div>
                <div class="weui_uploader_bd">
                    <ul class="weui_uploader_files">
                        <li class="weui_uploader_file" id="showPic" style="display:none;background-image:url(http://shp.qpic.cn/weixinsrc_pic/pScBR7sbqjOBJomcuvVJ6iacVrbMJaoJZkFUIq4nzQZUIqzTKziam7ibg/)"></li>
                    </ul>
                    <div class="weui_uploader_input_wrp" id="getPic"></div>
                </div>
            </div>
        </div>
    </div>
    <div class="weui_cells weui_cells_access" onclick="loc()">
        <a class="weui_cell">
            <div class="weui_cell_hd">
                <i class="iconfont icon-dizhi"></i>
            </div>
            <div class="weui_cell_bd weui_cell_primary">
                <p id="a-name">
                    选择位置
                </p>
            </div> <span class="weui_cell_ft"></span> </a>
    </div>
    <div class="weui_cell">
        <div class="weui_cell_bd weui_cell_primary">
            <textarea class="weui_textarea" placeholder="请点击上边选择一个和您最近的地点" rows="2" id="address"></textarea>
            <div class="weui_textarea_counter">
                <span>0</span>/200
            </div>
        </div>
    </div>
</div>
<input type="hidden" value="" id="lon" name="lon"/>
<input type="hidden" value="" id="lat" name="lat"/>
<input type="hidden" value="" id="logo" name="logo"/>
<div class="demos-content-padded">
    <a href="javascript:sb();" class="weui_btn  weui_btn_primary">确定</a>
</div>
<script src="/static/weui/script/api.js"></script>
<script src="/static/weui/script/H.js"></script>
<script src="/static/weui/script/jquery-2.1.4.js"></script>
<script src="/static/weui/script/jquery-weui.js"></script>
<script src="/static/weui/script/city-picker.js"></script>
<script>
    function sb() {
        var name = $("#name").val();
        var tel = $("#tel").val();
        var type = $("#type").val();
        var address = $("#address").val();
        var lon = $("#lon").val();
        var lat = $("#lat").val();
        var logo = $("#logo").val();
        if (name == '' || tel == '' || type == '') {
            $.alert('基本信息不完整')
        } else {
            if (address == '' || lon == '' || lat == '') {
                $.alert('位置信息不完整')
            } else {
                //alert(lon + lat)
                api.showProgress({
                    style : 'zoom',
                    animationType : 'fade',
                    title : '正在提交...',
                    text : '请稍等',
                    modal : false
                });
                api.ajax({
                    url : 'http://kd958.com/app/api/kaidian_post',
                    method : 'post',
                    data : {
                        values : {
                            name : name,
                            tel : tel,
                            type : type,
                            address : address,
                            lon : lon,
                            lat : lat
                        },
                        files : {
                            file : logo
                        }
                    }
                }, function(ret, err) {
                    if (ret) {
                        if (ret.err) {
                            api.toast({
                                msg : ret.info
                            });
                        } else {
                            api.execScript({
                                name : 'main',
                                frameName : 'shop',
                                script : 'my_shop()'
                            });
                            api.confirm({
                                title : ret.info,
                                msg : '请等待,我们会联系您',
                                buttons : ['去看看我的小店', '返回']
                            }, function(ret, err) {
                                if (ret) {
                                    if (ret.buttonIndex == 2) {
                                        api.closeWin({
                                        });
                                    } else {
                                        api.closeWin({
                                        });
                                    }
                                } else {
                                    alert(JSON.stringify(err));
                                }
                            });
                        }
                    } else {
                        api.alert({
                            msg : JSON.stringify(err)
                        });
                    }
                    api.hideProgress();
                });
            }
        }
    }


    $("#type").select({
        title : "选择店铺类型",
        items : ["零食", "日用", "快餐", "虚拟服务", "饮品", "其他"],
        onChange : function(d) {
            //console.log(this, d);
        },
        onClose : function() {
            //console.log("close");
        },
        onOpen : function() {
            //console.log("open");
        },
    });
    $("#getPic").click(function() {
        api.getPicture({
            //sourceType: 'camera',
            encodingType : 'jpg',
            mediaValue : 'pic',
            destinationType : 'url',
            allowEdit : true,
            quality : 80,
            saveToPhotoAlbum : false
        }, function(ret, err) {
            if (ret) {
                if (ret.data) {
                    $("#showPic").show();
                    //console.log(ret.data)
                    $("#showPic").css("background-image", "url(" + ret.data + ")");
                    $("#logo").val(ret.data)
                }
            } else {
                alert(JSON.stringify(err));
            }
        });
    });
    function loc() {
        H.openWin('amap_head', 'amap_head.html')
    }

    apiready = function() {
        api.addEventListener({
            name : 'set_address'
        }, function(ret, err) {
            if (ret) {
                data = ret.value;
                $("#a-name").text(data.name)
                if (data.real) {
                    $("#address").text(data.address)
                } else {
                    $("#address").text(data.address + data.name + '附近')
                }
                $("#lon").val(data.lon)
                $("#lat").val(data.lat)
                api.toast({
                    msg : '已经帮您自动填写地址,如果不满意可以修改'
                });
                setTimeout('$("#address").focus();', 300);
            } else {
                alert(JSON.stringify(err));
            }
        });
    }
</script>
</body>
</html>
